package com.mxwl.cbg.common.model.source.role;

import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;


/**
 * 角色的基本属性信息
 */
@Schema(description = "角色的基本属性信息")
@Data
public class AttributeBasic {
    /// 人物状态
    //用户id
    @Schema(description = "用户id")
    private Integer usernum;
    //用户id的长度
    @Schema(description = "用户id的长度")
    private Integer user_num_length;
    //角色名称
    @Schema(description = "角色名称")
    private String cName;
    // 造型\角色;
    @Schema(description = "造型\\角色")
    private Integer iIcon;
    //总经验
    @Schema(description = "总经验")
    private Long sum_exp;
    //角色等级
    @Schema(description = "角色等级")
    private Integer iGrade;
    //人气
    @Schema(description = "人气")
    private Integer iPride;
    //帮贡
    @Schema(description = "帮贡")
    private Integer iOrgOffer;
    //魔法
    @Schema(description = "魔法")
    private Integer iMp_Max;
    //帮派(门派)
    @Schema(description = "帮派(门派)")
    private Integer iSchool;
    //体质
    @Schema(description = "体质")
    private Integer iCor_All;
    //气血
    @Schema(description = "气血")
    private Integer iHp_Max;
    //魔力
    @Schema(description = "魔力")
    private Integer iMag_All;
    //命中
    @Schema(description = "命中")
    private Integer iAtt_All;
    //力量
    @Schema(description = "力量")
    private Integer iStr_All;
    //伤害
    @Schema(description = "伤害")
    private Integer iDamage_All;
    //耐力
    @Schema(description = "耐力")
    private Integer iRes_All;
    //防御
    @Schema(description = "防御")
    private Integer iDef_All;
    //敏捷
    @Schema(description = "敏捷")
    private Integer iSpe_All;
    //速度
    @Schema(description = "速度")
    private Integer iDex_All;
    //潜力--有可能--》iPoint，TA_iAllPoint，
    @Schema(description = "潜力--有可能--》iPoint，TA_iAllPoint")
    private Integer iPoint;
    //法防
    @Schema(description = "法防")
    private Integer iTotalMagDef_all;
    //法伤
    @Schema(description = "法伤")
    private Integer iTotalMagDam_all;
    // 原始种族1,2,3 人魔仙;
    @Schema(description = "原始种族1,2,3 人魔仙")
    private String ori_race;
    //持有经验
    @Schema(description = "持有经验")
    private Integer iUpExp;
    //属性加点方案
    @Schema(description = "属性加点方案")
    private Map<String, Map<String, Integer>> propKept;
    //属性点加点方案的总结
    @Schema(description = "属性点加点方案的总结")
    private List<String> prop_kept_desc;
    // 潜能果数量
    @Schema(description = "潜能果数量")
    private Integer iNutsNum;
    //月饼粽子的食用量
    @Schema(description = "月饼粽子的食用量")
    private Integer addPoint;
    //已获得机缘属性
    @Schema(description = "已获得机缘属性")
    private Integer jiyuan;
    //生死劫
    @Schema(description = "生死劫")
    private Integer nine_fight_level;
    //转职（飞升渡劫）
    @Schema(description = "转职（飞升渡劫）")
    private Integer iZhuanZhi;
    //化圣等级
    @Schema(description = "化圣等级")
    private Integer i3FlyLv;
    //记录飞升\华圣情况:0:为飞升,1:飞升,2:渡劫,3:化圣
    @Schema(description = "记录飞升\\华圣情况:0:为飞升,1:飞升,2:渡劫,3:化圣")
    private Integer zhuanZhi;
    //成就点数量
    @Schema(description = "成就点数量")
    private Integer AchPointTotal;
    // 历史门派;
    @Schema(description = "历史门派")
    private List<Integer> changesch;
    //新版乾元丹数量
    @Schema(description = "新版乾元丹数量")
    private Integer TA_iAllNewPoint;
    //旧版乾元丹数量
    @Schema(description = "旧版乾元丹数量")
    private Integer TA_iAllPoint;
    //bid
    @Schema(description = "bid")
    private Integer bid;
    //靓号
    @Schema(description = "靓号:梦幻西游,土豪金,是,未知,否")
    private String pretty_bid;

    //id说明
    @Schema(description = "id说明")
    private List<Integer> idbid_desc;

    /// 角色修炼及宠修====================================================================================================
    //修炼总和
    @Schema(description = "修炼总和")
    private Integer exp_count;
    //总宠修
    @Schema(description = "总宠修")
    private Integer pet_exp_count;
    //攻击
    @Schema(description = "攻击")
    private Integer iExptSki1;
    //防御
    @Schema(description = "防御")
    private Integer iExptSki2;
    //法术
    @Schema(description = "法术")
    private Integer iExptSki3;
    //抗法
    @Schema(description = "抗法")
    private Integer iExptSki4;
    //猎术
    @Schema(description = "猎术")
    private Integer iExptSki5;
    //攻击上限
    @Schema(description = "攻击上限")
    private Integer iMaxExpt1;
    //法术上限
    @Schema(description = "法术上限")
    private Integer iMaxExpt2;
    //防御上限
    @Schema(description = "防御上限")
    private Integer iMaxExpt3;
    //抗法上限
    @Schema(description = "抗法上限")
    private Integer iMaxExpt4;
    //宠物技能
    //攻击控制力
    @Schema(description = "攻击控制力")
    private Integer iBeastSki1;
    //防御控制力
    @Schema(description = "防御控制力")
    private Integer iBeastSki2;
    //法术控制力
    @Schema(description = "法术控制力")
    private Integer iBeastSki3;
    //抗法控制力
    @Schema(description = "抗法控制力")
    private Integer iBeastSki4;
    //御兽术
    @Schema(description = "御兽术")
    private Integer yu_shou_shu;//数据来自all_skills中的221技能

    /// 积分 其他=========================================================================
    //比武积分
    @Schema(description = "比武积分")
    private Integer HeroScore;
    //剑会积分
    @Schema(description = "剑会积分")
    private Integer sword_score;
    //神器积分
    @Schema(description = "神器积分")
    private Integer shenqi_score;
    //副本积分
    @Schema(description = "副本积分")
    private Integer dup_score;
    //三界功绩
    @Schema(description = "三界功绩")
    private Integer datang_feat;

    /// 输出=============================================================================================================
    private int fengYinMingZhongLv; // 封印命中等级
    private int zhiLiaoNengLi; // 治疗能力
    private int kuangBaoDengJi; // 狂暴等级
    private int wuLiBaoJiDengJi; // 物理暴击等级
    private int faShuBaoJiDengJi; // 法术暴击等级
    private int chuanCiDengJi; // 穿刺等级
    private int faShuShangHaiJieGuo; // 法术伤害结果
    private int duoBi; // 躲避
    private int lingLi; // 灵力
    //封印命中率
    @Schema(description = "封印命中率")
    private float fengYinMingZhongLvBFB = 0.0f;
    //物理暴击率
    @Schema(description = "物理暴击率")
    private float wuLiBaoJiDengJiBFB = 0.0f;
    //穿刺几率
    @Schema(description = "穿刺几率")
    private float chuanCiDengJiBFB = 0.0f;
    //狂暴几率
    @Schema(description = "狂暴几率")
    private float kuangBaoDengJiBFB = 0.0f;
    //法术暴击几率
    @Schema(description = "法术暴击几率")
    private float faShuBaoJiDengJiBFB = 0.0f;

    /// 抗性===========================================================================
    // 气血回复效果
    @Schema(description = "气血回复效果")
    private int qiXueHuiFuXiaoGuo;
    // 格挡值
    @Schema(description = "格挡值")
    private int geDangZhi;
    // 抵抗封印等级
    @Schema(description = "抵抗封印等级")
    private int diKangFengYinDengJi;
    // 抗法术暴击等级
    @Schema(description = "抗法术暴击等级")
    private int kangFaShuBaoJiDengJi;
    // 抗物理暴击等级
    @Schema(description = "抗物理暴击等级")
    private int kangWuLiBaoJi;
    //抗物理暴击几率
    @Schema(description = "抗物理暴击几率")
    private float kangWuLiBaoJiBFB = 0.0f;
    //抗法术暴击几率
    @Schema(description = "抗法术暴击几率")
    private float kangFaShuBaoJiDengJiBFB = 0.0f;
    //抵抗封印几率
    @Schema(description = "抵抗封印几率")
    private float diKangFengYinDengJiBFB = 0.0f;

    // 角色身上染色彩果数
    @Schema(description = "角色身上染色彩果数")
    private Integer iCGBodyAmount;
    // 角色所有彩果数
    @Schema(description = "角色所有彩果数")
    private Integer iCGTotalAmount;
    // 衣柜已保存染色方案数量
    @Schema(description = "衣柜已保存染色方案数量")
    private Integer iCGBoxAmount;

    //召唤兽心得技能总数
    @Schema(description = "召唤兽心得技能总数")
    private Integer sbook_skill_total;
    //已习得召唤兽心得技能数量
    @Schema(description = "已习得召唤兽心得技能数量")
    private Integer sbook_skill_num;
    @Schema(description = "拥有的房屋id")
    private String rent;
    @Schema(description = "拥有的房屋等级")
    private Integer rent_level;
    @Schema(description = "庭院等级")
    private Integer outdoor_level;

    @Schema(description = "牧区等级")
    private Integer farm_level;

    @Schema(description = "同袍")
    private Integer iMarry2;
    @Schema(description = "结婚")
    private Integer iMarry;


    // 社区相关
    private String commu_name;
    private Integer commu_gid;

    /**
     * 设置更多属性
     * 这里设置的就是角色的修炼的输出加成和宠物修炼的输出加成
     * 以及抗性的加成
     *
     * @param more_attr  原始json数据中的more_attr字段数据
     * @param role_level 角色等级
     */
    public void setMoreAttr(List<Map<String, Integer>> more_attr, int role_level) {
        for (Map<String, Integer> attr : more_attr) {
            Integer idx = attr.get("idx");
            switch (idx) {
                case 1:
                    this.fengYinMingZhongLv = attr.get("lv");
                    break;
                case 2:
                    this.diKangFengYinDengJi = attr.get("lv");
                    break;
                case 3:
                    this.zhiLiaoNengLi = attr.get("lv");
                    break;
                case 4:
                    this.qiXueHuiFuXiaoGuo = attr.get("lv");
                    break;
                case 5:
                    this.kuangBaoDengJi = attr.get("lv");
                    break;
                case 6:
                    this.wuLiBaoJiDengJi = attr.get("lv");
                    break;
                case 7:
                    this.faShuBaoJiDengJi = attr.get("lv");
                    break;
                case 8:
                    this.chuanCiDengJi = attr.get("lv");
                    break;
                case 9:
                    this.kangWuLiBaoJi = attr.get("lv");
                    break;
                case 10:
                    this.kangFaShuBaoJiDengJi = attr.get("lv");
                    break;
                case 11:
                    this.geDangZhi = attr.get("lv");
                    break;
                case 12:
                    this.faShuShangHaiJieGuo = attr.get("lv");
                    break;
                case 13:
                    this.duoBi = attr.get("lv");
                    break;
                case 14:
                    this.lingLi = attr.get("lv");
                    break;
                default:
                    break;
            }
        }
        this.fengYinMingZhongLvBFB = this.calculateThePercentage25(fengYinMingZhongLv, role_level);
        this.wuLiBaoJiDengJiBFB = this.calculateThePercentage(wuLiBaoJiDengJi, role_level);
        this.chuanCiDengJiBFB = this.calculateThePercentage(chuanCiDengJi, role_level);
        this.kuangBaoDengJiBFB = this.calculateThePercentage(kuangBaoDengJi, role_level);
        this.kangWuLiBaoJiBFB = this.calculateThePercentage(kangWuLiBaoJi, role_level);
        this.kangFaShuBaoJiDengJiBFB = this.calculateThePercentage(kangFaShuBaoJiDengJi, role_level);
        this.diKangFengYinDengJiBFB = this.calculateThePercentage25(diKangFengYinDengJi, role_level);
        this.faShuBaoJiDengJiBFB = this.calculateThePercentage(faShuBaoJiDengJi, role_level);
    }

    private float calculateThePercentage25(float value, int role_level) {
        double result = (10.0 * value) / Math.max(30, role_level + 25);
        DecimalFormat df = new DecimalFormat("#.00");
        return Float.parseFloat(df.format(result));
    }

    private float calculateThePercentage(float value, int role_level) {
        double result = (10.0 * value) / Math.max(30, role_level);
        DecimalFormat df = new DecimalFormat("#.00");
        return Float.parseFloat(df.format(result));
    }
}
